package com.easycar.common.manager;



import com.easycar.common.base.AppActivity;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 *
 * Activity 管理器
 */

public class ActivityManager implements  IManager<AppActivity> {
    private  static List<AppActivity> mList=new LinkedList<>();
    private static final  ActivityManager  sManger=new   ActivityManager();


    /**
     *
     * @return
     */
    public static ActivityManager  getInstance(){
        return  sManger;
    }

    /**
     * 向队列添加当前Activity
     * @param appActivity
     */
    @Override
    public void add(AppActivity appActivity) {
        mList.add(appActivity);
    }

    /**
     * 队列移除当前Activity
     * @param appActivity
     */
    @Override
    public void remove(AppActivity appActivity) {
        mList.remove(appActivity);
    }

    /**
     * Activity 队列清除所有消息
     */
    @Override
    public void clear() {
        ListIterator<AppActivity> iterator = mList.listIterator();
        AppActivity activity;
        while (iterator.hasNext()) {
            activity = iterator.next();
            if (activity != null) {
                activity.finish();
            }
        }
    }
}
